package com.mysoap.medicine.client;

import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.bs.entity.MedicineIn;
import com.bs.entity.MedicineInfo;
import com.bs.entity.MedicineOut;
import com.mysoap.medicine.service.MedicineInfoSoapStub;
import com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineInfoRequest;
import com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineQuery;
import com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineQueryResponse;
import com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineSave;
import com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineStorage;



public class MedicineInfoClient {
	public static void main(String[] args) throws  Exception {
		String address = "http://localhost:8080/MySoap/services/MedicineInfoSoap";
		MedicineInfoSoapStub stub = new MedicineInfoSoapStub(address);
		/**save
		 * 
		 
		MedicineSave medicineSave= new MedicineSave();
		MedicineInfoRequest request = new MedicineInfoRequest();
		Date date = new Date();
		String dateStr = DateHelper.getTimeStamp(date, new String[]{"yyyy-MM-dd HH:mm:ss"});
		
		com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineCategory mc = new MedicineCategory();
		mc.setCategoryDesc("12344");
		mc.setCategoryName("hello");
		//request.setMedicineCategory(mc);
		
		MedicineStorage ms = new MedicineStorage();
		ms.setMedicineCode("1000");
		ms.setMedicineQuantity(100);
		
		MedicineInfo mi = new MedicineInfo();
		
		System.out.println("dateStr"+dateStr);
		com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineInfo param1 = new com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineInfo();
		param1.setBuyTime(Calendar.getInstance());
		param1.setMedicineCode("0001");
		param1.setMedicineFactory("广东制药");
		param1.setMedicineDesc("感冒药");
		param1.setMedicineFactoryAddress("广东");
		param1.setMedicineName("999感冒灵");
		param1.setMedicinePrice(20L);
	//	param1.setMedicineCategory(mc);
		request.setMedicineInfo(param1);
	//	param1.setMedicineStorage(ms);
		
	
	//	request.setMedicineStorage(ms);
		
		
		
		Set<MedicineIn> param = new HashSet<MedicineIn>();
		com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineIn[] medicineInArr = new com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineIn[1];
		medicineInArr[0] = new com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineIn();
		System.out.println(medicineInArr[0]);
		medicineInArr[0].setInCount(12);
		medicineInArr[0].setInRecordTime(Calendar.getInstance());
	//	medicineInArr[0].setMedicineInfo(param1);
	request.setMedicineIns(medicineInArr);
		
		Set<MedicineOut> paramout = new HashSet<MedicineOut>();
		com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineOut[] medicineoutArr = new com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineOut[1];
		medicineoutArr[0] = new com.mysoap.medicine.service.MedicineInfoSoapStub.MedicineOut();
//		System.out.println(medicineInArr[0]);
//		medicineInArr[0].setInCount(12);
//		medicineInArr[0].setInRecordTime(Calendar.getInstance());
		medicineoutArr[0].setMedicineInfo(param1);
	//	request.setMedicineOuts(medicineoutArr);
		
		
		medicineSave.setMedicineRequest(request);
		System.out.println("--------------dd--------------");
		stub.medicineSave(medicineSave);
		
		*/
		
		/**查询
		 * MedicineQuery medicineQuery1 = new MedicineQuery();
		MedicineInfoRequest request1 = new MedicineInfoRequest();
		request1.setUpdateFlag(1);
		medicineQuery1.setRequest(request1);
		System.out.println(medicineQuery1.getRequest());
		MedicineQueryResponse response = stub.medicineQuery(medicineQuery1);
		System.out.println("------------------after-----"+response.get_return());
		 */
		
		
		MedicineQuery medicineQuery = new MedicineQuery();
		MedicineInfoRequest request = new MedicineInfoRequest();
		request.setUpdateFlag(5);
		request.setMedicineId(5L);
		request.setBuyTime(DateHelper.getTimeStamp(new Date(), new String[]{"yyyy-MM-dd HH:mm:ss"}));
		request.setMedicineDesc("一次3片，一日2次");
		request.setMedicineFactory("上海");
		request.setMedicineFactoryAddress("上海");
		request.setMedicineName("头孢颗粒");
		request.setMedicinePrice(20);
		request.setMeidcineCode("2000");
		
//		MedicineCategory param = new MedicineCategory();
//		param.setCategoryId(2L);
//		param.setCategoryDesc("1级");
//		request.setMedicineCategory(param );
		medicineQuery.setRequest(request);
		MedicineQueryResponse response = stub.medicineQuery(medicineQuery);
		System.out.println(response.get_return().getDiscription());
	}
}
